﻿Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page
    Dim cn As New SqlConnection(ConfigurationSettings.AppSettings("conn"))

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex
    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label2.Text = Session("username")
        Try
            Dim cmd As New SqlCommand("select imageid,imageurl,title,uploadby from imagetable order by uploaddate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()

            'over here i have used the same cmd command because it will not make any difference
            cmd = New SqlCommand("select comment.imageid,comment,imageurl,commentby from comment,imagetable  where comment.imageid=imagetable.imageid order by cdate desc", cn)
            ds = New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView2.DataSource = ds
            GridView2.DataBind()
        Catch
        End Try


    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Response.Redirect("details page.aspx?id=" + GridView1.Rows(GridView1.SelectedIndex).Cells(0).Text)
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim cmd As New SqlCommand("select imageid,imageurl,title,uploadby from imagetable where uploadby='" + DropDownList1.SelectedValue + "' order by uploaddate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView1.DataSource = ds
            GridView1.DataBind()
        Catch
        End Try
    End Sub


    Protected Sub GridView2_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView2.PageIndexChanging
        GridView2.PageIndex = e.NewPageIndex

    End Sub

    Protected Sub GridView2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView2.SelectedIndexChanged
        Response.Redirect("details page.aspx?id=" + GridView2.Rows(GridView2.SelectedIndex).Cells(0).Text)

    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim cmd As New SqlCommand("select comment.imageid,comment,imageurl,commentby from comment,imagetable  where comment.imageid=imagetable.imageid and commentby='" + DropDownList2.SelectedValue + "' order by cdate desc", cn)
            Dim ds As New SqlDataSource(cn.ConnectionString, cmd.CommandText)
            GridView2.DataSource = ds
            GridView2.DataBind()
        Catch ex As Exception

        End Try
        
    End Sub
End Class
